<?php
    /*
     * @Author: KingMin 
     * @Date: 2022-3-12 11:38:01 
     * @Last Modified by:   KingMin 
     * @Last Modified time: 2022-3-12 11:38:08https://www.jxkuaiche.top/
     * @The authors website: https://www.kingmin.cn  
     */
    header('Access-Control-Allow-Headers:x-requested-with,content-type'); 

    require_once ("./admin.php");
    $APIURL=$_SERVER['REQUEST_URI'];
    $APIURL=explode("?",$APIURL);
    $APIURL=explode("/",$APIURL[0]);
    @$a=$APIURL[3];
    @$postData=json_decode(file_get_contents('php://input'), true);
    switch ($a){
        case 'test':
            // $m=new Menu_Model();
            // $m=new Menu_Model();
            // $menu = $m->getAllrolemenu();
            // global $CACHE;
            // $menu = $CACHE->readCache('menus');
            // $CACHE=Cache::getInstance();
            // $menu = $CACHE->readCache('menuRole');
            // $data=getRead('km_sys_notice');
            // $data=Group_Model::getGroupCacheList();
            // $data=Option::getGroup('web_banner');
            // ajaxReturn (200,'操作成功',$menu); 
            // ajaxReturn (200,'操作成功',isAuthority('admin','routine/inform/index')); 
            // ajaxReturn (200,'操作成功',clearCache('options')); 
            // ajaxReturn (200,'操作成功',getcode("",123)); 
            // $path=PASH_ROOT."/content/ceshi/123.php";
            // ajaxReturn (200,'操作成功',touch($path)); 
            // $dt=[["token"=>"9e715846fc710455484d141fcbeed50e","time"=>"2022-12-01 13:27:22"],["token"=>"4d9fc44b5386ae3c629f968fb2174308","time"=>"2022-12-01 13:33:18"]];
            // inArrayKeyFun($k="token",$v="9e715846fc710455484d141fcbeed50e",$dt);
            // ajaxReturn (200,'操作成功',getOperationLog()); 
            // database();
            $attr = array(
                'db_id' => 14,
            );
            $config=[
                    "port"=>'6379',
                    "host"=>'127.0.0.1',
                    "auth"=>'',
                ];
            // $r=new Redis_Model();
            // $dt=Redis::getInstance($attr);
            // ajaxReturn (200,'操作成功',$dt); https://www.kancloud.cn/a173512/php_note/1344411
            // RedisService::init(3);
            if(!RedisService::op()){
                RedisService::init(3);
            }
            // RedisService::setUser(['id'=>1001,'age'=>18]);3xmyjWaH0WS85Ii2xS8SC3cIwezc;;;token_98F13708210194C475687BE6106A3B84
            //             @$key=$_GET['k'];
            // RedisService::setToken("token_g0m8jzrRhDG85Ii2xS8SBH0Py+rc");
            RedisService::setToken("webLogin_1");
            // RedisService::setUser(55);
            // RedisService::delUser();
            // echo "用户数据<br/>";
            // var_dump(RedisService::getUser());
            // echo '<br/>';
            // echo "token:<br/>";
            // var_dump(RedisService::getToken());
            // echo '<br/>';
            // echo "在线用户数:<br/>";
            // var_dump(RedisService::onLineNumber("webLogin_*"));
            // var_dump(RedisService::dequeue());
            // RedisService::dbselect(5);
            // echo $r;
            
            // var_dump(RedisService::op());
                        // $r=new Redis_Model();
                    // $r->getInstance(['db_id'=>1]);
            // ajaxReturn(200,'ok',RedisService::ttl());
            // ajaxReturn(200,'ok',RedisService::test());
            ajaxReturn(200,'ok',RedisService::getUser());
        
        break;
        case 'code':
            @$dt['w']=$_GET['w']??0;
            @$dt['h']=$_GET['h']??0;
            @$dt['f']=$_GET['f']??0;
            
            getcode(@$APIURL[4],@$APIURL[5],$dt);
        break;
        case 'index':
            ajaxReturn(200,'OK',adminindex());
        break;
        case 'user'://用户模块
            @$userType=$APIURL[4];
            switch ($userType){
                case 'loginInfo':
                    ajaxReturn(200,'OK',loginInfo());
                break;
                case 'signIn':
                    $data=signIn($postData);
                    if($data){
                        ajaxReturn (200,'操作成功',$data); 
                    }else{
                        ajaxReturn (500,'操作失败',$data); 
                    }
                break;
                case 'loginPhoneUser':
                    $data=loginPhoneUser($postData);
                    if($data){
                        ajaxReturn (200,'操作成功',$data); 
                    }else{
                        ajaxReturn (500,'操作失败',$data); 
                    }
                break;
                case 'sendSmsCode':
                    $data=phoneLoginSend($postData);
                    if($data){
                        ajaxReturn (200,'操作成功',$data); 
                    }else{
                        ajaxReturn (500,'操作失败',$data); 
                    }
                break;
                case 'isLogin':
                    ajaxReturn (200,'操作成功',isLogin(false)); 
                break;
                case 'logOut':
                    logOut(); 
                break;
                case 'clearCache'://清除缓存
                    $dt=clearCache();
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'getinFormList'://获取通知信息
                    $dt=getinFormList($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'addInForm'://发布通知信息
                    $dt=addInForm($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'onLineList'://获取在线用户
                    $dt=getUserOnLineList($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'userList'://获取用户列表
                    $dt=getUserList($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'roleList'://获取角色列表
                    $dt=getRoleList($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'upRoleDetail'://修改角色信息
                    $dt=upRoleDetail($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'addRoleDetail'://修改角色信息
                    $dt=addRoleDetail($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'menuList'://获取树形菜单列表
                    $dt=getMenuList();
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'adminList'://获取管理员列表信息
                    $dt=getAdminList($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'upAdminDetail'://修改管理员信息
                    $dt=upAdminDetail($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'memberList'://获取用户列表信息
                    $dt=getMemberList($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'upMemberDetail'://修改用户信息
                    $dt=upMemberDetail($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'addMemberDetail'://新增用户信息
                    $dt=addMemberDetail($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'personalData'://获取个人资料
                    $dt=getPersonalData();
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'upPersonalData'://修改个人资料
                    $dt=upPersonalData($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                default:
                    ajaxReturn(300,'FAIL',$a);
            }
        break;
        case 'pageInfo'://页面前置模块
            @$page=$APIURL[4];
            switch ($page){
                case 'attachment':
                    ajaxReturn(200,'OK',getPagesAttachment());
                break;
                case 'log':
                    @$path=$_GET['path'];
                    ajaxReturn(200,'OK',getPagesLog($path));
                break;
                case 'role':
                    @$path=$_GET['path'];
                    ajaxReturn(200,'OK',getPagesRole($path));
                break;
                case 'member':
                    @$path=$_GET['path'];
                    ajaxReturn(200,'OK',getPagesMember($path));
                break;
                case 'database':
                    @$path=$_GET['path'];
                    ajaxReturn(200,'OK',getPagesDatabase($path));
                break;
                default:
                    ajaxReturn(300,'没有当前页面信息',$page);
            }
        break;
        case 'log'://日志模块
            @$page=$APIURL[4];
            switch ($page){
                case 'user':
                    ajaxReturn(200,'OK',getPagesAttachment());
                break;
                case 'operationLog':
                    $dt=getOperationLog($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'loginLog':
                    $dt=getLoginLog($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'errorLog':
                    $dt=getErrorLog($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                default:
                    ajaxReturn(300,'没有当前日志信息',$page);
            }
        break;
        case 'attachment'://附件操作模块
            @$page=$APIURL[4];
            switch ($page){
                case 'fileList':
                    $dt=getFileList($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'addFile':
                    $dt=addFile($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'upFile':
                    $dt=upFile($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'accessoryList':
                    $dt=getAccessoryList($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'upAccessory':
                    $dt=upAccessory($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'moveAccessory':
                    $dt=moveAccessory($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'delAccessory':
                    $dt=delAccessory($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                default:
                    ajaxReturn(300,'没有当前页面信息',$page);
            }
        break;
        case 'loginInfo':
           ajaxReturn(200,'OK',loginInfo());
        break;
        case 'getmenu':
           ajaxReturn(200,'OK',getAllmenu());
        break;
        case 'system':
             @$page=$APIURL[4];
            switch ($page){
                case 'configData':
                    @$id=$_GET['id'];
                    ajaxReturn(200,'OK',getConfigData($id));
                break;
                case 'configDetail':
                    @$id=$_GET['id'];
                    ajaxReturn(200,'OK',getConfigDetail($id));
                break;
                case 'configTab':
                    $exploit=$_GET['exploit'];
                    ajaxReturn(200,'OK',getConfigTab($exploit));
                break;
                case 'upConfigDetail':
                    $dt=upConfigDetail($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'uploadConfigTab':
                    $dt=uploadConfigTab($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'addConfigTab':
                    $dt=addConfigTab($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'addConfig':
                    $dt=addConfigDetail($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'upConfig':
                    $dt=upConfig($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'oneConfigTab':
                    @$isAll=$_GET['isAll'];
                    ajaxReturn(200,'OK',getOneConfigTab(@$isAll));
                break;
                case 'addGroup':
                    $dt=addGroup($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'groupList':
                    $dt=getGroupList($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'upGroup':
                    $dt=upGroup($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'groupDataList':
                    $dt=getGroupDataList($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'addGroupData':
                    $dt=addGroupData($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'upGroupData':
                    $dt=upGroupData($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'dataBaseList':
                    $dt=getDataBaseList($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'operationDb':
                    $dt=operationDb($postData);
                    if($dt){
                       ajaxReturn (200,'操作成功', $dt); 
                    }else{
                       ajaxReturn (400,'失败'); 
                    }
                break;
                case 'getRead':
                    @$tablename=$_GET['tablename'];
                    ajaxReturn(200,'OK',getRead(@$tablename));
                break;
                default:
                    ajaxReturn(300,'没有当前页面信息',$page);
            }
        break;
        default:
            // echo json_encode($APIURL);
            // header("HTTP/1.1 404 Not Found");
            // header("HTTP/1.1 404 Not Found");exit;
            // header("Location://admin.kingmin.cn/404");exit;
            ajaxReturn (1001,'非正常调用,验证不通过,ADMIN', $APIURL); 
    }